<?php

use App\Category;
use App\Topic;
use App\User;
use Illuminate\Database\Seeder;

class TopicsTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $faker = app(Faker\Generator::class);
        $user_ids = User::all()->pluck('id')->toArray();
        $category_ids = Category::all()->pluck('id')->toArray();
        $topics = factory(Topic::class,100)->make()->each(function ($topic,$index)
            use ($user_ids,$category_ids,$faker) {
            $topic->user_id = $faker->randomElement($user_ids);
            $topic->category_id = $faker->randomElement($category_ids);
        });
        Topic::query()->insert($topics->toArray());
    }
}
